Repository navigation
Conversation
Start every output batch's string view blocks at 64 KiB again instead of continuing the doubling from earlier batches, and shrink a block that is less than half full whenever one is closed. Closes apache#12305 Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
BatchCoalescercopies the strings of view arrays it gc's into blocks whose size doubles from 8 KiB to 1 MiB and never starts over. After a few output batches, every batch gets at least one 1 MiB block however few bytes it holds. Blocks closed early, when a push that can reuse its buffers arrives, keep their full capacity.get_array_memory_sizereports that capacity, so the longer a coalescer runs, the more memory each row appears to use. In DataFusion, a hash join building on a hash-repartitioned scan accounted 3–4x process RSS. The issue has a standalone repro and measurements.What changes are included in this PR?
BufferSourcestarts at 64 KiB and doubles up to 1 MiB (or the size a single request needs, if larger).finish()gives each output batch a new source, so block sizes depend only on that batch.push_completedcloses every block (previously six places did this by hand). It shrinks a block to its contents when less than half of it is used.The 64 KiB start and the per-batch doubling are a trade-off: sizing every block at
max(need, 64 KiB)accounted a bit less, but with long strings copied in small pushes it made up to 13x more buffers per batch, andtakeon the concatenated output, which clones the buffer list, got up to 1.9x slower. With doubling, that case stays within 5 buffers per batch and matchesmain(numbers in #12305).Are these changes tested?
Yes:
test_string_view_copied_blocks_track_each_batchpushes smalltakes of a large array through one coalescer and checks that no output batch's buffers have more than twice the capacity of the strings they hold. Onmainit fails at the third batch (131072 bytes of capacity for 40000).BufferSourceunit tests cover the new sizing.test_string_view_batch_large_slice_compact,_many_small_compact,_many_small_boundary,_large_small) now expect one block shrunk to its contents instead of three doubling ones.coalesce_kernels(utf8viewcases,mainvs this branch, pinned to 8 cores of a shared host): median change +0.3% across the 103 cases with non-inline strings, spread −22% to +22%. The 21 cases with only inline strings (max_string_len=8), which never reach the changed code, spread −23% to +7% (median +0.6%), so that's this host's noise level, and I found no consistent change either way. A run on a quieter machine would be welcome.Are there any significant user-facing changes?
No API changes. Coalesced view arrays may have a different number and size of data buffers than before.
AI usage disclosure
I used Claude Code (Anthropic) for this PR:
The same patch is carried downstream on arrow-select 59.3.2, where it passes that project's test suite.
cc @alamb (author of the StringView coalescer and
BufferSource, #7650) and @Dandandan (#9132, avoiding overallocation in coalesce views). Would you be able to take a look?